﻿<!DOCTYPE html>
<html ng-app="demoApp" lang="en">
<head>
    <title id='Description'>AngularJS Chart Export to JPEG or PNG. In order to export the Chart you will need a browser which supports HTML5.</title>
   <meta name="description" content="This is an example of AngularJS Chart. Chart export to JPEG and PNG formats." />
    <link rel="stylesheet" type="text/css" href="../../../jqwidgets/styles/jqx.base.css" />
    <script type="text/javascript" src="../../../scripts/angular.min.js"></script> <script type="text/javascript" src="../../../scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxdraw.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxchart.core.js"></script><script type="text/javascript" src="../../../jqwidgets/jqxangular.js"></script>
    <script type="text/javascript" src="../../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../../scripts/demos.js"></script>
    <script type="text/javascript">
        var demoApp = angular.module("demoApp", ["jqwidgets"]);
        demoApp.controller("demoController", function ($scope) {

            function getExportServer() {
                return 'http://www.jqwidgets.com/export_server/export.php';
            }

            // prepare data source
            var source =
            {
                datatype: "csv",
                datafields: [
                    { name: 'Country' },
                    { name: 'GDP' },
                    { name: 'DebtPercent' },
                    { name: 'Debt' }
                ],
                url: '../../sampledata/gdp_dept_2010.txt'
            };

            var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } });

            // prepare jqxChart settings
            var settings = {
                title: "Economic comparison",
                description: "GDP and Debt in 2010",
                showLegend: true,
                enableAnimations: true,
                padding: { left: 5, top: 5, right: 5, bottom: 5 },
                titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
                source: dataAdapter,
                xAxis:
                    {
                        dataField: 'Country',
                        showGridLines: true
                    },
                colorScheme: 'scheme01',
                seriesGroups:
                    [
                        {
                            type: 'column',
                            columnsGapPercent: 50,
                            valueAxis:
                            {
                                unitInterval: 5000,
                                displayValueAxis: true,
                                description: 'GDP & Debt per Capita($)'
                            },
                            series: [
                                    { dataField: 'GDP', displayText: 'GDP per Capita' },
                                    { dataField: 'Debt', displayText: 'Debt per Capita' }
                                ]
                        },
                        {
                            type: 'line',
                            valueAxis:
                            {
                                unitInterval: 10,
                                displayValueAxis: false,
                                description: 'Debt (% of GDP)'
                            },
                            series: [
                                    { dataField: 'DebtPercent', displayText: 'Debt (% of GDP)' }
                                ]
                        }

                    ]
            };

            $scope.chartSettings = settings;

            $scope.jpegButtonClick = function () {
                // call the export server to create a JPEG image
                $scope.chartSettings.apply('saveAsJPEG', 'myChart.jpeg', getExportServer());
            };
            $scope.pngButtonClick = function()
            {
                // call the export server to create a PNG image
                $scope.chartSettings.apply('saveAsPNG', 'myChart.png', getExportServer());
            };
        });
    </script>
</head>
<body ng-controller="demoController">
    <jqx-chart jqx-settings="chartSettings" style="width: 850px; height: 500px;">
    </jqx-chart>
    <div style='margin-top: 10px;'>
        <jqx-button jqx-on-click="jpegButtonClick(event)" style='float: left;'>Save As JPEG</jqx-button>
        <jqx-button jqx-on-click="pngButtonClick(event)" style='float: left; margin-left: 5px;'>Save As PNG</jqx-button>
    </div>
</body>
</html>
